package com.gps.pojo;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.SimpleFormatter;

public class GPS implements Serializable {

    private static final Long serialVersionId = 1L;

    private final String header;
    private String time; // UTC 时间，hhmmss.sss（时分秒）格式
    private double longitude;
    private boolean isN;
    private double latitude;
    private boolean isE;
    private int status;     // GPS 状态：0=未定位，1=非差分定位，2=差分定位，6=正在估算
    private String satellite;  // 正在使用解算位置的卫星数量（00-12）（前面的0 也将被传输）
    private float hdop;     // HDOP水平精度因子（0.5-99.9）
    private float altitude;   // 海拔高度（-9999.9-99999.9）
    private float heightEarthEllipsoidGeoid;                // 地球椭球面相对大地水准面的高度
    private int differentialTime; //差分时间（从最近一次接收到差分信号开始的秒数，如果不是差分定位将为空）
    private String differentialStationID; // 差分站ID 号0000-1023（前面的0 也将被传输，如果不是差分定位将为空）

    public GPS(double latitude, boolean isN, double longitude, boolean isE, int status, String satellite, float hdop,
               float altitude, float heightEarthEllipsoidGeoid, int differentialTime, String differentialStationID) {
        this.header = "$GPGGA";
        this.time = new SimpleDateFormat("hhmmss").format(new Date());
        this.longitude = longitude;
        this.latitude = latitude;
        this.isN = isN;
        this.isE = isE;
        this.status = status;
        this.satellite = satellite;
        this.hdop = hdop;
        this.altitude = altitude;
        this.heightEarthEllipsoidGeoid = heightEarthEllipsoidGeoid;
        this.differentialTime = this.status == 2 ? differentialTime : -1;
        this.differentialStationID = differentialStationID;
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        result.append(this.header + ",")
                .append(this.time).append(".000,")
                .append(this.latitude + ",").append(isN ? "N," : "S,")
                .append(this.longitude + ",").append(isE ? "E," : "E,")
                .append(this.status + ",").append(satellite + ",")
                .append(hdop + ",").append(altitude + ",")
                .append("M,")
                .append(heightEarthEllipsoidGeoid + ",").append("M,").append(differentialTime == -1 ? "," : differentialTime + ",")
                .append(differentialStationID);
        return new String(result);
    }

    public String getHeader() {
        return header;
    }

    public String getTime() {
        return time;
    }

    public void setTime() {
        this.time = new SimpleDateFormat("hhmmss").format(new Date());;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public boolean isN() {
        return isN;
    }

    public void setN(boolean n) {
        isN = n;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public boolean isE() {
        return isE;
    }

    public void setE(boolean e) {
        isE = e;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getSatellite() {
        return satellite;
    }

    public void setSatellite(String satellite) {
        this.satellite = satellite;
    }

    public float getHdop() {
        return hdop;
    }

    public void setHdop(float hdop) {
        this.hdop = hdop;
    }

    public float getAltitude() {
        return altitude;
    }

    public void setAltitude(float altitude) {
        this.altitude = altitude;
    }

    public float getHeightEarthEllipsoidGeoid() {
        return heightEarthEllipsoidGeoid;
    }

    public void setHeightEarthEllipsoidGeoid(float heightEarthEllipsoidGeoid) {
        this.heightEarthEllipsoidGeoid = heightEarthEllipsoidGeoid;
    }

    public int getDifferentialTime() {
        return differentialTime;
    }

    public void setDifferentialTime(int differentialTime) {
        this.differentialTime = differentialTime;
    }

    public String getDifferentialStationID() {
        return differentialStationID;
    }

    public void setDifferentialStationID(String differentialStationID) {
        this.differentialStationID = differentialStationID;
    }
}
